function ToolsAndConsumablesController($scope,$state,Notification,FileUploader,ToolsService,context,ErrorUtils){

	$scope.companyUuid = context.getEmployee().company.uuid;
	
	$scope.toolsList = [];
	
	$scope.applications = [
	                       	{name:'Select Application Purpose',value:0},
	                       	{name:'Buffing & Polishing',value:1},
	                   		{name:'Carpet Extractor',value:2},
	                   		{name:'Scrubbing',value:3},
	                   		{name:'Scrubbing & Shampooing',value:4},
	                   		{name:'Steam Generator',value:5},
	                   		{name:'Sweeper cum Scrubber',value:6},
	                   		{name:'Sweeping',value:7},
	                   		{name:'Vacuuming',value:8},
	                   		{name:'Other',value:9}
	                       ];
	
	//Default Selection
	$scope.application = $scope.applications[0];
	
	$scope.submitTool = function(){
		
		var data = 	"application="+$scope.application.name+"&" +
					"description="+$scope.description+"&" +
					"brand="+$scope.brand+"&" +
					"model="+$scope.model+"&" +
					"origin="+$scope.origin+"&" +
					"packing="+$scope.packing+"&" +
					"companyUuid="+$scope.companyUuid;
		
		var save = ToolsService.save(data);
		
		save.$promise.then(
				function(data){
					if(data.meta.code == 200){
						console.log("Data:",data);
						Notification.success({message: 'Record saved successfully.', title: 'Success'});
						for(index in data.data){
							$scope.toolsList.push(data.data[index]);
						}
					}
					else{
						Notification.error({message:ErrorUtils.getMessageByErrorCode(data.meta.code), title: 'Error'});
					}
					
				},
				function(error){					
					Notification.error({message: "Some error occurred. Please try again later.", title: 'Error'});
				});
	};
	
	$scope.getToolsList = function(){
		$scope.toolsList = [];
		var get = ToolsService.get({id:$scope.companyUuid});
		
		get.$promise.then(
				function(data){
					if(data.meta.code == 200){
						console.log("Data:",data);
						for(index in data.data){
							$scope.toolsList.push(data.data[index]);
						}
					}
					else{
						Notification.error({message:ErrorUtils.getMessageByErrorCode(data.meta.code), title: 'Error'});
					}
					
				},
				function(error){
					Notification.error({message: "Some error occurred. Please try again later.", title: 'Error'});
				});
	};
	
	$scope.deleteTool = function(uuid,index){
		var del = ToolsService.delete({id:uuid});
		
		del.$promise.then(
				function(data){
					if(data.meta.code == 200){
						console.log("Data:",data);
						$scope.deleteItemFromToolsList(index);
					}
					else{
						Notification.error({message:ErrorUtils.getMessageByErrorCode(data.meta.code), title: 'Error'});
					}
					
				},
				function(error){
					Notification.error({message: "Some error occurred. Please try again later.", title: 'Error'});
				});
	};
	
	$scope.deleteItemFromToolsList = function(index){
		var from 	= index;
		var to		= 0;
		var rest = $scope.toolsList.slice((to || from) + 1 || $scope.toolsList.length);
		$scope.toolsList.length = from < 0 ? $scope.toolsList.length + from : from;
		$scope.toolsList.push.apply($scope.toolsList, rest);
	}
	
	
	
	$scope.getToolsList();
}


angular.module('supplier.toolsandconsumables',['ngAnimate','ui.router','ui-notification','angularFileUpload'])
	.controller('ToolsAndConsumablesController',['$scope','$state','Notification','FileUploader','ToolsService','context','ErrorUtils',ToolsAndConsumablesController]);